package org.innovasix.educational.javap.domain.constantpool;

import org.innovasix.educational.javap.domain.datatypes.cp_info;
import org.innovasix.educational.javap.domain.datatypes.u1;
import org.innovasix.educational.javap.domain.datatypes.u2;
import org.innovasix.educational.javap.domain.parser.ByteQueue;

/**
 * <p>
 * <b><i>From the JVM specification:</i></b><br/>
 * The Constant_Class_info structure is used to represent a class or an
 * interface.
 * </p>
 * 
 * @see <a
 *      href="http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.4.1">4.4.1.
 *      The CONSTANT_Class_info Structure</a>
 * 
 * @author sven.mentl@gmail.com
 * 
 */
public class CONSTANT_Class_info extends cp_info {

	public CONSTANT_Class_info(ByteQueue byteQueue) {
		name_index = byteQueue.pollTwoBytes("CONSTANT_Class_info constructor");
	}

	/**
	 * <p>
	 * <b><i>From the JVM specification:</i></b><br/>
	 * The tag item has the value CONSTANT_Class(7).
	 * </p>
	 */
	final u1 tag = new u1(ConstantPoolTags.CONSTANT_Class.decimalValue());

	/**
	 * <p>
	 * <b><i>From the JVM specification:</i></b><br/>
	 * The value of the name_index item must be a valid index into the
	 * constant_pool table. The constant_pool entry at that index must be a
	 * CONSTANT_Utf8_info structure representing a valid binary class or
	 * interface name encoded in internal form.
	 * </p>
	 * </p> <b><i>Additional notes:</i></b><br/>
	 * There is no specific cp_info structure for arrays. Arrays are also
	 * encoded as CONSTANT_Class_info structure. The String value referenced by
	 * the name_index is the descriptor of the array type.<br/>
	 * E.g.: {@code [[I} is the class name representing the type of
	 * {@code int[][]} <br/>
	 * E.g.: {@code [Ljava/lang/Thread} is the class name representing the type
	 * of {@code Thread[]} </p>
	 * 
	 */
	u2 name_index;
	
	public String toString(){
		StringBuilder sb = new StringBuilder();
		sb.append("CONSTANT_Class_info [");
		sb.append("name_index: #");
		sb.append(name_index);
		sb.append("]");
		return sb.toString();
	}

}
